//package reflect.reflect.handles.collections;
//
//import com.fasterxml.jackson.core.json.async.NonBlockingJsonParser;
//import lombok.SneakyThrows;
//import reflect.exceptions.HandleException;
//import reflect.handles.OAble;
//import reflect.handles.classes.ClassO;
//import reflect.handles.exception.ExceptionOF;
//import reflect.handles.object.ObjectO;
//
//import java.lang.invoke.MethodHandle;
//import java.lang.invoke.MethodHandles;
//import java.lang.invoke.MethodType;
//import java.util.ArrayList;
//import java.util.Collection;
//import java.util.HashSet;
//import java.util.List;
//import java.util.function.Function;
//import java.util.function.Predicate;
//import java.util.stream.Stream;
//
///**
// * @Author: Qiao Hang
// * @CreateDate: 2020/12/3 下午4:31
// * @UpdateDate:
// * @Description:
// */
//public class ListO implements OAble {
//
//    static {
//        try {
//            Class<?> loadHandleOperate = ListO.class.getClassLoader().loadClass("reflect.handles.HandleSupplier");
//            ListO.lookup = (MethodHandles.Lookup)loadHandleOperate.getDeclaredField("methodLookup").get(null);
//        }catch (Throwable e){
//            /**/
//        }
//    }
//
//    static {
//        findHandles();
//
//        ArrayList aa;
//
//        aa.clear();
//        int size = aa.size();
//        boolean contains = aa.contains(obj);
//        Object o = aa.get(1);
//        int i = aa.indexOf(obj);
//        int i1 = aa.lastIndexOf(obj);
//        boolean empty = aa.isEmpty();
//        List list = aa.subList(1, 2);
//        Stream stream = aa.stream();
//        Object[] objects = aa.toArray();
//
//
//        boolean add = aa.add(22);
//    }
//
//    public static MethodHandles.Lookup lookup;
//
//    public static MethodHandle add;
//    public static MethodHandle addIn;
//    public static MethodHandle addAll;
//    public static MethodHandle addAllIn;
//
//    public static MethodHandle rmv;
//    public static MethodHandle rmvIn;
//    public static MethodHandle rmvAll;
//    public static MethodHandle rmvPredicate;
//
//    public static MethodHandle clear;
//    public static MethodHandle size;
//    public static MethodHandle contains;
//    public static MethodHandle getIdx;
//    public static MethodHandle idxOf;
//    public static MethodHandle lIdxOf;
//    public static MethodHandle isEmpty;
//    public static MethodHandle subList;
//    public static MethodHandle stream;
//    public static MethodHandle toArray;
//
//    @SneakyThrows(Throwable.class)
//    private static void findHandles() {
//        add = lookup.findVirtual(List.class,"add",MethodType.methodType(boolean.class,Object.class));
//        addIn = lookup.findVirtual(List.class,"add",MethodType.methodType(void.class,int.class,Object.class));
//        addAll = lookup.findVirtual(List.class,"addAll",MethodType.methodType(boolean.class, Collection.class));
//        addAllIn = lookup.findVirtual(List.class,"addAll",MethodType.methodType(boolean.class, int.class,Collection.class));
//
//        rmv = lookup.findVirtual(List.class,"remove",MethodType.methodType(boolean.class,Object.class));
//        rmvIn = lookup.findVirtual(List.class,"remove",MethodType.methodType(ObjectO.class,int.class));
//        rmvAll = lookup.findVirtual(List.class,"removeAll",MethodType.methodType(boolean.class,Collection.class));
//        rmvPredicate = lookup.findVirtual(List.class,"removeIf",MethodType.methodType(boolean.class, Predicate.class));
//
//        clear = lookup.findVirtual(List.class,"clear",MethodType.methodType(void.class));
//        size = lookup.findVirtual(List.class,"size",MethodType.methodType(int.class));
//        contains = lookup.findVirtual(List.class,"contains",MethodType.methodType(boolean.class,Object.class));
//        getIdx = lookup.findVirtual(List.class,"get",MethodType.methodType(Object.class,int.class));
//        idxOf = lookup.findVirtual(List.class,"indexOf",MethodType.methodType(int.class,Object.class));
//        lIdxOf = lookup.findVirtual(List.class,"lastIndexOf",MethodType.methodType(int.class,Object.class));
//        isEmpty = lookup.findVirtual(List.class,"isEmpty",MethodType.methodType(boolean.class));
//        subList = lookup.findVirtual(List.class,"subList",MethodType.methodType(List.class,int.class,int.class));
//        stream = lookup.findVirtual(List.class,"stream",MethodType.methodType(Stream.class));
//        toArray = lookup.findVirtual(List.class,"toArray",MethodType.methodType(Object[].class));
//    }
//
//    public static Function<Object[],Boolean> add_ = (params) -> {
//        try {
//            if(params.length != 2)
//            return (Boolean) add.invoke();
//        } catch (HandleException deepError){
//            throw deepError;
//        } catch (Throwable throwable) {
//            throw ExceptionOF.runtimeExc_.apply("ListOF.add_ : occur an error -> " + throwable.getMessage());
//        }
//    };
//
//
//
//
//    public static void main(String[] args) throws Throwable{
//
//        Object invoke = ClassO.newInstance.bindTo(ArrayList.class).invoke();
//        Object invoke2 = ClassO.newInstance.bindTo(HashSet.class).invoke();
//
//        ArrayList arrayList = ArrayList.class.newInstance();
//        HashSet hashSet = HashSet.class.newInstance();
//        System.out.println("---");
//    }
//
//}
